<template>
  <div class="show page">
    <div class="banner bg-full" @click="router.push({ name: 'home' })"></div>
    <div class="title">第十届春蕾杯比武大赛海选集锦</div>
    <div class="main">
      <div class="list">
        <div class="col" v-for="i in 2" :key="i">
          <template v-for="(item, index) in list" :key="item.id">
            <div
              class="item"
              v-if="(i === 1 && index % 2 === 0) || (i === 2 && index % 2 !== 0)"
              @click="handlePreview(index)"
            >
              <img
                :src="`${item.raceUrl}?x-oss-process=image/resize,lfit,h_375,w_375`"
                :alt="item.name"
                @error="handleImageError"
              />
            </div>
          </template>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { getRandomUserList } from '@/api/index.js'
import { useRouter } from 'vue-router'
import { api as viewerApi } from 'v-viewer'

const router = useRouter()

const list = ref([])

getRandomUserList().then((res) => {
  list.value = res.data
})

const handlePreview = (index) => {
  viewerApi({
    images: list.value.map((item) => item.raceUrl),
    options: {
      initialViewIndex: index,
      title: false
    }
  })
}

const handleImageError = (err) => {
  err.target.closest('.item').remove()
}
</script>

<style lang="less" scoped>
.show {
  justify-content: flex-start;
}

.banner {
  width: 100%;
  height: 698px;
  background-image: url(../assets/img/show/banner.png);
}

.title {
  width: 100%;
  font-size: 60px;
  font-weight: bold;
  padding: 50px;
  box-sizing: border-box;
  background: #fff;
}

.main {
  background: #fff;
  flex: 1;
  width: 100%;
  overflow: auto;
}

.list {
  width: 100%;
  display: flex;
  justify-content: space-between;
  box-sizing: border-box;
  padding: 0 50px 50px;
  gap: 50px;

  .col {
    display: flex;
    flex: 1;
    flex-direction: column;
    row-gap: 50px;
  }

  .item {
    width: 100%;
    box-sizing: border-box;
    img {
      width: 100%;
      display: block;
    }
  }
}
</style>
